home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: cs.chalmers.se!news.chalmers.se!sunic!uunet!europa.eng.gtefsd.com!darwin.sura.net!news-feed-1.peachnet.edu!concert!sas!mozart.unx.sas.com!walker
- From: walker@twix.unx.sas.com (Doug Walker)
- Subject: Re: Exec RawDoFmt
- Originator: walker@twix.unx.sas.com
- Sender: news@unx.sas.com (Noter of Newsworthy Events)
- Message-ID: <C6xCB7.3CG@unx.sas.com>
- Date: Wed, 12 May 1993 17:23:30 GMT
- References: <C6v9wr.CvH@unx.sas.com> <1993May12.133954.3498@imada.ou.dk>
- Nntp-Posting-Host: twix.unx.sas.com
- Organization: SAS Institute Inc.
- Lines: 77
-
-
- In article <1993May12.133954.3498@imada.ou.dk>, breese@monet.imada.ou.dk (Bjorn Reese) writes:
- |> > In article <Miles_Willmek.0jfy@saug.UUCP>, Miles_Willmek@saug.UUCP (Miles
- |> Willmek) writes:
- |> > >Can somebody help me with Exec's RawDoFmt() function. I cant seem to get
- |> > >string types (%s, %b)to output anything (except spaces if I specify a field
- |> > >width.
- |> > >
- |> > >I'm pretty sure its not my code. Does RawDoFmt() work?
- |>
- |> The parameter for %s (strings) must be a pointer to the string,
- |> not the string itself, as in Printf().
-
- The "string itself" and the "pointer to the string" are actually the
- same thing in C. A string literal is really a char * that points to
- the beginning of the string. Hence, the parameter for %s is the same
- for Printf() and RawDoFmt().
-
- Here is example code that uses RawDoFmt() to print a string and a
- decimal value. BE CAREFUL when printing integers if you use four-byte
- integers (the default for SAS/C and most other compilers) - unlike
- normal C, you must use %ld instead of %d when printing "int" variables
- and constants if you use RawDoFmt().
-
- #include <stdarg.h>
- #include <string.h>
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/exec_pragmas.h>
-
- extern struct Library *DOSBase;
-
- int myprintf(char *ctl, ...);
-
- int main(void)
- {
- myprintf("This is a %s (%ld)\n", "test", 42);
- return 0;
- }
-
- int myprintf(char *ctl, ...)
- {
- char buffer[256];
- va_list args;
-
- va_start(args, ctl);
-
- /*********************************************************/
- /* NOTE: The string below is actually CODE that copies a */
- /* value from d0 to A3 and increments A3: */
- /* */
- /* move.b d0,(a3)+ */
- /* rts */
- /* */
- /* It is essentially the callback routine needed */
- /* by RawDoFmt. */
- /*********************************************************/
-
- RawDoFmt(ctl, args, (void (*))"\x16\xc0\x4e\x75", buffer);
-
- va_end(args);
-
- Write(Output(), buffer, strlen(buffer));
-
- return 0;
- }
-
-
- --
- ***** / walker@unx.sas.com
- *|_o_o|\\ Doug Walker< BIX, Portal: djwalker
- *|. o.| || \ CompuServe: 71165,2274
- | o |//
- ======
- Any opinions expressed are mine, not those of SAS Institute, Inc.
-